from django.http import HttpResponse
from django.shortcuts import render
from django.utils.decorators import method_decorator
from django.views.generic import View
# Create your views here.
# url(r'^template_view/$',views.TemplateView)
class TemplateView(View):

    def get(self,request):
        context = {
            'city':'北京',
            'alist':[2,3,4],
            'adict':{'age':10},
        }
        return render(request,'index.html',context=context)

def my_decorator(view_func):
    """装饰器"""
    def wrapper(request,*args,**kwargs):
        print('我的装饰器生效了')
        return view_func(request,*args,**kwargs)
    return wrapper


# 可以只装类视图中指定的方法
#url(r'^demoview/$',views.DemoView.as_view()),
@method_decorator(my_decorator, name='get')
class DemoView(View):
    """定义类视图"""
    #@my_decorator
    def get(self,request):
        return HttpResponse('get逻辑业务')

    def post(self,request):
        return HttpResponse('post逻辑业务')